package com.keshan.controller;

import com.keshan.utils.DateUtil;
import com.keshan.pojo.Fall;
import com.keshan.pojo.FallJson;
import com.keshan.utils.Msg;
import com.keshan.service.FallServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author keshan
 * @date 2022/10/20 - 18:47
 */
@CrossOrigin
@Controller
@RequestMapping("/fall")
public class FallController {
    @Autowired
    FallServices fallServices;

    @RequestMapping("/insertfall")
    @ResponseBody
    public Msg insertBySelectiveToFall(@RequestBody FallJson fallJson){
        Fall fall = new Fall();
        fall.setAddress(fallJson.getAddress());
        fall.setCity(fallJson.getCity());
        fall.setDeviceType(fallJson.getDevice_type());
        fall.setImei(fallJson.getImei());
        fall.setLat(fallJson.getLat());
        fall.setLon(fallJson.getLon());
        fall.setTimeBegin(DateUtil.StringToDate(fallJson.getTime_begin_str()));
        fall.setType(fallJson.getType());
        int result = fallServices.insertBySelectiveToFall(fall);
        return Msg.success().add("result",result);
    }

}
